﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace ZSZ.CommonMvc
{
   public class JiSuSmsSend
    {
        public string Appkey { get; set; }
        public string Content { get; set; }
        public JiSuSmsResult SendSms(string shouji) {
            string result = string.Empty;
            try
            {
                HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.Create("https://api.jisuapi.com/sms/send");
                wbRequest.Method = "POST";
                wbRequest.ContentType = "application/x-www-form-urlencoded";   //如果要发送Json数据就是application/json
                string form = string.Format("mobile={0}&content={1}&appkey={2}", shouji, Content, Appkey);
                using (Stream requestStream = wbRequest.GetRequestStream())
                {
                    using (StreamWriter swrite = new StreamWriter(requestStream))
                    {
                        swrite.Write(form);
                    }
                }
                HttpWebResponse wbResponse = (HttpWebResponse)wbRequest.GetResponse();
                using (Stream responseStream = wbResponse.GetResponseStream())
                {
                    using (StreamReader sread = new StreamReader(responseStream))
                    {
                        result = sread.ReadToEnd();
                    }
                }
            }
            catch (Exception e) { }
            JiSuSmsResult ssss =JsonConvert.DeserializeObject<JiSuSmsResult>(result);
            return ssss;
        }
    }
}
